import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Controls.Material 2.12
import QtQuick.Layouts 1.12

import "functions.js" as Utils

Page {
	property var control_button_diameter: (function_panel_grid.width / 3)
	Timer {
		id: fake_power_on_timer
		interval: 5000
		running: false
		repeat: false
		onTriggered: {
			Utils.powerSwitch(true)
			power_switch_busyIndicator.visible = false
			power_switch_roundbutton.visible = true
		}
	}
	Timer {
		id: fake_power_off_timer
		interval: 1000
		running: false
		repeat: false
		onTriggered: {
			Utils.powerSwitch(false)
			power_switch_busyIndicator.visible = false
			power_switch_roundbutton.visible = true
		}
	}

	ColumnLayout {
		anchors.fill: parent
		anchors.margins: 10
		Rectangle {
			id: brief_information_rect
			z: 10
			Layout.fillWidth: true
			Layout.fillHeight: true
			Layout.margins: 5
			color: "#ffffff"
			radius: 20
			ColumnLayout {
				anchors.fill: parent
				RowLayout {
					Layout.fillHeight: true
					Layout.fillWidth: true
					Label {
						id: power_state_name_label
						padding: 10
						Layout.fillHeight: true
						Layout.fillWidth: true
						Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
						verticalAlignment: Text.AlignVCenter
						horizontalAlignment: Text.AlignLeft
						text: qsTr("设备状态")
					}
					Label {
						id: power_state_data_label
						padding: 10
						Layout.fillHeight: true
						Layout.fillWidth: true
						Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
						verticalAlignment: Text.AlignVCenter
						horizontalAlignment: Text.AlignLeft
						text: qsTr("正常运行")
					}
				}
				RowLayout {
					Layout.fillHeight: true
					Layout.fillWidth: true
					Label {
						id: fan_state_name_label
						padding: 10
						Layout.fillHeight: true
						Layout.fillWidth: true
						Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
						verticalAlignment: Text.AlignVCenter
						horizontalAlignment: Text.AlignLeft
						text: qsTr("风道状态")
					}
					Label {
						id: fan_state_data_label
						padding: 10
						Layout.fillHeight: true
						Layout.fillWidth: true
						Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
						verticalAlignment: Text.AlignVCenter
						horizontalAlignment: Text.AlignLeft
						text: qsTr("风速：0.23 m/s")
					}
				}
			}
		}
		Rectangle {
			id: remote_control_panel_rect
			z: 10
			Layout.fillWidth: true
			Layout.minimumHeight: parent.height / 3 * 2
			Layout.margins: 5
			color: "#ffffff"
			radius: 20
			GridLayout {
				z: 11
				id: remote_control_panel_grid
				anchors.fill: parent
				columns: 2
				BusyIndicator {
					id: power_switch_busyIndicator
					visible: false
					Layout.preferredWidth: control_button_diameter
					Layout.preferredHeight: control_button_diameter
					Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
					RoundButton {
						anchors.fill: parent
						flat: true
						highlighted: true
						display: AbstractButton.TextUnderIcon
						text: qsTr("设备开关")
						icon.height: basic_button_diameter / 2
						icon.width: basic_button_diameter / 2
						icon.source: "./Images/drawable/power_settings_new-black-24dp.svg"
					}
				}
				RoundButton {
					id: power_switch_roundbutton
					Layout.preferredWidth: control_button_diameter
					Layout.preferredHeight: control_button_diameter
					Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
					font.family: defaultFontFamily
					font.capitalization: Font.MixedCase
					highlighted: true
					display: AbstractButton.TextUnderIcon
					text: qsTr("设备开关")
					icon.height: basic_button_diameter / 2
					icon.width: basic_button_diameter / 2
					icon.source: "./Images/drawable/power_settings_new-black-24dp.svg"
					onClicked: {
						if (power_state_data_label.text == "正常运行") {
							visible = false
							power_switch_busyIndicator.visible = true
							fake_power_off_timer.start()
						} else {
							visible = false
							power_switch_busyIndicator.visible = true
							fake_power_on_timer.start()
						}
					}
				}
				RoundButton {
					id: wind_control_roundbutton
					Layout.preferredWidth: control_button_diameter
					Layout.preferredHeight: control_button_diameter
					Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
					font.family: defaultFontFamily
					font.capitalization: Font.MixedCase
					highlighted: true
					display: AbstractButton.TextUnderIcon
					text: qsTr("风速控制")
					icon.height: basic_button_diameter / 2
					icon.width: basic_button_diameter / 2
					icon.source: "./Images/drawable/toys-black-24dp.svg"
					onClicked: {

					}
				}
				RoundButton {
					id: purify_settings_roundbutton
					Layout.preferredWidth: control_button_diameter
					Layout.preferredHeight: control_button_diameter
					Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
					font.family: defaultFontFamily
					font.capitalization: Font.MixedCase
					highlighted: true
					display: AbstractButton.TextUnderIcon
					text: qsTr("净化设置")
					icon.height: basic_button_diameter / 2
					icon.width: basic_button_diameter / 2
					icon.source: "./Images/drawable/eco-24px.svg"
					onClicked: {

					}
				}
				RoundButton {
					id: more_settings_roundbutton
					Layout.preferredWidth: control_button_diameter
					Layout.preferredHeight: control_button_diameter
					Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
					font.family: defaultFontFamily
					font.capitalization: Font.MixedCase
					highlighted: true
					display: AbstractButton.TextUnderIcon
					text: qsTr("更多设置")
					icon.height: basic_button_diameter / 2
					icon.width: basic_button_diameter / 2
					icon.source: "./Images/drawable/more_horiz-black-24dp.svg"
					onClicked: {

					}
				}
			}
		}
	}
}
